package Sort;

public class SelectionSort {
    //选择排序
    public static void main(String[] args) {
        int[] arr={1,9,5,7,6,8,2,3,4,2,0,6};
        selectionSort(arr);

    }

    private static void selectionSort(int[] arr) {
        //外循环：控制进行多少轮的循环
        for (int i = 0; i < arr.length-1; i++) {
            //内循环：一轮的循环
            for (int j = i+1; j < arr.length; j++) {
                if(arr[i]>arr[j]){
                    int temp=arr[j];
                    arr[j]=arr[i];
                    arr[i]=temp;
                }
            }
            printarr(arr);
            System.out.println();
        }

    }

    public static void printarr(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}
